package controler;

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import dialog.HouseDialog;

public class NbHouseListener implements ChangeListener {
	HouseDialog hd;
	public NbHouseListener (HouseDialog hd){
		this.hd=hd;
	}
	public void stateChanged(ChangeEvent e) {
		JSlider slide = (JSlider)e.getSource();
		if(slide.getValueIsAdjusting()){
			
			if(slide.equals(hd.slider1)){
				if(slide.getValue()==0){
					if(hd.slider2.getValue()>1){
						hd.slider2.setValue(0);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()>1){
						hd.slider3.setValue(0);
					}
				}
				else if(slide.getValue()==1){
					if(hd.slider2.getValue()>2){
						hd.slider2.setValue(1);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()>2){
						hd.slider3.setValue(1);
					}
				}

				else if(slide.getValue()==2){
					if(hd.slider2.getValue()<1||hd.slider2.getValue()>3){
						hd.slider2.setValue(2);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()<1||hd.slider3!=null&&hd.slider3.getValue()>3){
						hd.slider3.setValue(2);
					}
				}

				else if(slide.getValue()==3){
					if(hd.slider2.getValue()<2||hd.slider2.getValue()>4){
						hd.slider2.setValue(3);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()<2||hd.slider3!=null&&hd.slider3.getValue()>4){
						hd.slider3.setValue(3);
					}
				}

				else if(slide.getValue()==4){
					if(hd.slider2.getValue()<3){
						hd.slider2.setValue(4);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()<3){
						hd.slider3.setValue(4);
					}
				}
				else{
					if(hd.slider2.getValue()<4){
						hd.slider2.setValue(4);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()<4){
						hd.slider3.setValue(4);
					}
				}
				int j = slide.getValue();
				System.out.println(j);
			}
			else if(slide.equals(hd.slider2)){
				if(slide.getValue()==0){
					if(hd.slider1.getValue()>1){
						hd.slider1.setValue(0);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()>1){
						hd.slider3.setValue(0);
					}
				}
				else if(slide.getValue()==1){
					if(hd.slider1.getValue()>2){
						hd.slider1.setValue(1);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()>2){
						hd.slider3.setValue(1);
					}
				}
				else if(slide.getValue()==2){
					if(hd.slider1.getValue()<1||hd.slider1.getValue()>3){
						hd.slider1.setValue(2);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()<1||hd.slider3!=null&&hd.slider3.getValue()>3){
						hd.slider3.setValue(2);
					}
				}
				else if(slide.getValue()==3){
					if(hd.slider1.getValue()<2||hd.slider1.getValue()>4){
						hd.slider1.setValue(3);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()<2||hd.slider3!=null&&hd.slider3.getValue()>4){
						hd.slider3.setValue(3);
					}
				}
				else if(slide.getValue()==4){
					if(hd.slider1.getValue()<3){
						hd.slider1.setValue(4);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()<3){
						hd.slider3.setValue(4);
					}
				}
				else{
					if(hd.slider1.getValue()<4){
						hd.slider1.setValue(4);
					}
					if(hd.slider3!=null&&hd.slider3.getValue()<4){
						hd.slider3.setValue(4);
					}
				}
			}
			else if(slide.equals(hd.slider3)){
				if(slide.getValue()==0){
					if(hd.slider1.getValue()>1||hd.slider2.getValue()>1){
						hd.slider1.setValue(0);
						hd.slider2.setValue(0);
					}
				}
				else if(slide.getValue()==1){
					if(hd.slider1.getValue()>2||hd.slider2.getValue()>2){
						hd.slider1.setValue(1);
						hd.slider2.setValue(1);
					}
				}
				else if(slide.getValue()==2){
					if(hd.slider1.getValue()<1||hd.slider2.getValue()<1||hd.slider1.getValue()>3||hd.slider2.getValue()>3){
						hd.slider1.setValue(2);
						hd.slider2.setValue(2);
					}
				}
				else if(slide.getValue()==3){
					if(hd.slider1.getValue()<2||hd.slider2.getValue()<2||hd.slider1.getValue()>4||hd.slider2.getValue()>4){
						hd.slider1.setValue(3);
						hd.slider2.setValue(3);

					}
				}
				else if(slide.getValue()==4){
					if(hd.slider1.getValue()<3||hd.slider2.getValue()<3){
						hd.slider1.setValue(4);
						hd.slider2.setValue(4);
					}
				}
				else{
					if(hd.slider1.getValue()<4||hd.slider2.getValue()<4){
						hd.slider1.setValue(4);
						hd.slider2.setValue(4);
					}
				}
			}
			else if(slide.equals(hd.slider4)){
				if(slide.getValue()==0){
					if(hd.slider5.getValue()>1){
						hd.slider5.setValue(0);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()>1){
						hd.slider6.setValue(0);
					}
				}
				else if(slide.getValue()==1){
					if(hd.slider5.getValue()>2){
						hd.slider5.setValue(1);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()>2){
						hd.slider6.setValue(1);
					}
				}

				else if(slide.getValue()==2){
					if(hd.slider5.getValue()<1||hd.slider5.getValue()>3){
						hd.slider5.setValue(2);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()<1||hd.slider6!=null&&hd.slider6.getValue()>3){
						hd.slider6.setValue(2);
					}
				}

				else if(slide.getValue()==6){
					if(hd.slider5.getValue()<2||hd.slider5.getValue()>4){
						hd.slider2.setValue(3);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()<2||hd.slider6!=null&&hd.slider6.getValue()>4){
						hd.slider6.setValue(3);
					}
				}

				else if(slide.getValue()==4){
					if(hd.slider5.getValue()<3){
						hd.slider5.setValue(4);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()<3){
						hd.slider6.setValue(4);
					}
				}
				else{
					if(hd.slider5.getValue()<4){
						hd.slider5.setValue(4);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()<4){
						hd.slider6.setValue(4);
					}
				}
				int j = slide.getValue();
				System.out.println(j);
			}
			else if(slide.equals(hd.slider5)){
				if(slide.getValue()==0){
					if(hd.slider4.getValue()>1){
						hd.slider4.setValue(0);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()>1){
						hd.slider6.setValue(0);
					}
				}
				else if(slide.getValue()==1){
					if(hd.slider4.getValue()>2){
						hd.slider4.setValue(1);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()>2){
						hd.slider6.setValue(1);
					}
				}
				else if(slide.getValue()==2){
					if(hd.slider4.getValue()<1||hd.slider4.getValue()>3){
						hd.slider4.setValue(2);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()<1||hd.slider6!=null&&hd.slider6.getValue()>3){
						hd.slider6.setValue(2);
					}
				}
				else if(slide.getValue()==3){
					if(hd.slider4.getValue()<2||hd.slider4.getValue()>4){
						hd.slider4.setValue(3);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()<2||hd.slider6!=null&&hd.slider6.getValue()>4){
						hd.slider6.setValue(3);
					}
				}
				else if(slide.getValue()==4){
					if(hd.slider4.getValue()<3){
						hd.slider4.setValue(4);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()<3){
						hd.slider6.setValue(4);
					}
				}
				else{
					if(hd.slider4.getValue()<4){
						hd.slider4.setValue(4);
					}
					if(hd.slider6!=null&&hd.slider6.getValue()<4){
						hd.slider6.setValue(4);
					}
				}
			}
			else if(slide.equals(hd.slider6)){
				if(slide.getValue()==0){
					if(hd.slider4.getValue()>1||hd.slider5.getValue()>1){
						hd.slider4.setValue(0);
						hd.slider5.setValue(0);
					}
				}
				else if(slide.getValue()==1){
					if(hd.slider4.getValue()>2||hd.slider5.getValue()>2){
						hd.slider4.setValue(1);
						hd.slider5.setValue(1);
					}
				}
				else if(slide.getValue()==2){
					if(hd.slider4.getValue()<1||hd.slider5.getValue()<1||hd.slider4.getValue()>3||hd.slider5.getValue()>3){
						hd.slider4.setValue(2);
						hd.slider5.setValue(2);
					}
				}
				else if(slide.getValue()==3){
					if(hd.slider4.getValue()<2||hd.slider5.getValue()<2||hd.slider4.getValue()>4||hd.slider5.getValue()>4){
						hd.slider4.setValue(3);
						hd.slider5.setValue(3);
					}
				}
				else if(slide.getValue()==4){
					if(hd.slider4.getValue()<3||hd.slider5.getValue()<3){
						hd.slider4.setValue(4);
						hd.slider5.setValue(4);
					}
				}
				else{
					if(hd.slider4.getValue()<4||hd.slider5.getValue()<4){
						hd.slider4.setValue(4);
						hd.slider5.setValue(4);
					}
				}
			}
			else
				System.out.println("rien ne se passe");
		}
	}

}
